package com.ruicar.afs.cloud.contract.gateway.processor.result;

import cn.hutool.json.JSONObject;
import com.ruicar.afs.cloud.common.core.constant.CommonConstants;
import com.ruicar.afs.cloud.contract.gateway.beans.SystemDefine;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: Lee
 * @date: 2020/5/11 19:39
 * @description:
 */
@Component
public class IcosToCmsConvertProcessor implements ResultConvertProcessor {

    @Override
    public void convert(SystemDefine systemDefine,JSONObject jsonObject) {
        Map res = jsonObject.getByPath(systemDefine.getGateWaySystemMapping().getResponseAlias(), Map.class);
        if(res!=null){
            if(CommonConstants.SUCCESS.equals(res.get("code"))){
                res.put("success",1);
                res.remove("code");
            } else {
                res.put("success",0);
                res.put("code",null);
                res.put("message",res.get("msg"));
                res.remove("msg");
                res.remove("data");
            }
        }
        jsonObject.put(systemDefine.getGateWaySystemMapping().getResponseAlias(),res);
    }

    @Override
    public String key() {
        return "icos-to-cms";
    }
}
